﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace LINQPad.OpenAccess.Infrastructure
{
    /// <summary>
    /// Service locator interface.
    /// </summary>s
    public interface IServiceLocator : IDisposable
    {
        /// <summary>
        /// Gets an instance for the specified service type.
        /// </summary>
        /// <param name="serviceType">Type of the service.</param>
        /// <returns>
        /// The instance.
        /// </returns>
        object Get( Type serviceType );
        /// <summary>
        /// Gets an instance for the specified type.
        /// </summary>
        /// <typeparam name="T">The type of the instance.</typeparam>
        /// <returns>
        /// The instance.
        /// </returns>
        T Get<T>( );
        /// <summary>
        /// Gets all available instances for the specified type.
        /// </summary>
        /// <typeparam name="T">The type of the instance.</typeparam>
        /// <returns>
        /// The instance.
        /// </returns>
        IEnumerable<T> GetAll<T>( );
        /// <summary>
        /// Injects the dependencies into the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        void Inject( object instance );
        /// <summary>
        /// Tries to get an instance for the specified service type.
        /// </summary>
        /// <param name="serviceType">Type of the service.</param>
        /// <returns>
        /// The instance or <c>null</c>.
        /// </returns>
        object TryGet( Type serviceType );
        /// <summary>
        /// Tries to get an instance for the specified type.
        /// </summary>
        /// <typeparam name="T">The type of the instance.</typeparam>
        /// <returns>
        /// The instance or <c>null</c>.
        /// </returns>
        T TryGet<T>( );
    }
}
